let data;

// 搜索商品
function showSuggestions(query) {
    const suggestions = document.getElementById('suggestions');
    suggestions.innerHTML = '';
    if (query.length === 0) {
        return;
    }
    for (const id in data) {
        if (data[id].includes(query)) {
            const suggestionItem = document.createElement('div');
            suggestionItem.className = 'suggestion-item';
            suggestionItem.textContent = data[id];
            suggestionItem.onclick = () => selectProduct(id);
            suggestions.appendChild(suggestionItem);
        }
    }
}

function selectProduct(id) {
    sessionStorage.setItem("id",id);
    window.location.href = "info.html";
}

// 获取所有商品名字
getGoodsName();
function getGoodsName() {
    $.ajax({
        url: "/goods",
        type: "get",
        data: {num: 10},
        dataType: "json",
        success: function (dataString) {
            data = JSON.parse(dataString);
        }
    });
}